package com.twu.biblioteca.processor;

import com.twu.biblioteca.controller.LibraryController;
import com.twu.biblioteca.controller.MovieController;
import com.twu.biblioteca.controller.UserController;
import com.twu.biblioteca.io.InputReader;
import com.twu.biblioteca.io.InputValidator;
import com.twu.biblioteca.model.Item;
import com.twu.biblioteca.model.Library;
import com.twu.biblioteca.model.User;
import com.twu.biblioteca.ui.ItemView;
import com.twu.biblioteca.util.Messages;

import java.util.List;

/**
 * Created by madhu on 2/5/14.
 */
public class CheckoutMovieMenuProcessor implements MenuProcessor {

    @Override
    public void processLibraryMenu(LibraryController libraryController) {
        if(!User.isLoggedIn()) UserController.promptForLogin(libraryController.getLibraryView());
        else returnMovie(getMovieNameToReturn(), libraryController.getLibrary().getMovies());
    }

    public void returnMovie(String movieNameToReturn, List<Item> movies) {
        new MovieController().checkoutMovie(movieNameToReturn, movies);
    }

    public String getMovieNameToReturn() {
        ItemView itemView = new ItemView();
        itemView.displayMessage(Messages.movieNamePromptMessage);
        String input;
        while(true) {
            input = new InputReader().getUserInput();
            if(InputValidator.isEmpty(input)) itemView.displayMessage(Messages.emptyInputMessage);
            else break;
        }
        return input;
    }
}
